package com.lifang.imsoa.util;

import com.lifang.imsoa.entity.ErrorResponse;

import lombok.Getter;
import lombok.Setter;

public enum HXErrorCodeEnum {
	INVALID_GRANT(404,	"invalid_grant","user not found","用户不存在", 111),
	INVALID_GRANT2(400,	"invalid_grant","invalid password","密码无效", 222),
	DUPLICATE_UNIQUE(400,	"duplicate_unique_property_exists","","用户名已存在", 112),
	SERVICE_RESOURCE_NOT_FOUND(404,"service_resource_not_found", "","用户不存在", 111),
	REQUEST_ENTITY_TOO_LARGE(413,"Request Entity Too Large","","请求体过大", 333),
	ILLEGAL_ARGUMENT(400,	"ILLEGAL_ARGUMENT","","参数不正确", 444),
	NO_HXID(400,"required_property_not_found","","用户不存在", 111),
			
			
		
	NULL(-1, "","","",-1),
	;
	@Setter @Getter
	private int status;
	@Setter @Getter
	private String error;
	@Setter @Getter
	private String error_description;
	
	@Setter @Getter
	private String message;
	@Setter @Getter
	private Integer responseNo;

	private HXErrorCodeEnum(int status, String error,String error_description,String message,Integer responseNo) {
		this.status = status;
		this.error = error;
		this.error_description = error_description;
		this.message = message;
		this.responseNo = responseNo;
	}

	public static HXErrorCodeEnum getErrorEnumByStatus(ErrorResponse errorResponse){
		for(HXErrorCodeEnum errorEnum:HXErrorCodeEnum.values()){
			if(errorEnum.getStatus()==errorResponse.getStatusCode() && errorEnum.getError().equals(errorResponse.getError())){
				if(errorEnum.getError_description().equals(errorResponse.getError_description()) || errorEnum.getError_description().equals(""))
				return errorEnum;
			}
		}
		return null;
	}
}
